<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ include file="/taglibs.jsp"%>
<%@taglib uri="/WEB-INF/tld/pageutil.tld" prefix="pu"%>
<%@taglib uri="http://java.sun.com/jstl/core_rt" prefix="c-rt"%>
${pu:listAdd('theOrderId', param.orderId) }
${pu:reqSet('ops', pu:queryByHql('from OrderProduct where orderId=?', pu:arrayGet('theOrderId'), null)) }
<c-rt:set var="tmall_safeQty" value="${pu:menuOption('SystemValue', 'tmall_safeQty')}" scope="request"/>
<h1>
修改淘宝订单
</h1>
<br/>
${message }
<br/>
<script>
function checkForm(){
	if(confirm('确认修改订单?')){
		document.updateOrderForm.submit();
	}else{
		//do nothing
	}
}
</script>
<form name="updateOrderForm" action="<c-rt:url value="/tmall/updateOrder.do"/>" method="post">
<h2>加送赠品</h2>
<h3 style="color:red">(若订单已有该赠品，则不是加数量而是直接调整数量)</h3>
<table width="320">
<tr><td>
<table class="tb-data">
<tr>
<th></th><th>赠品名称</th><th>数量</th>
</tr>
<c-rt:forEach items="${presentSpecs}" var="pspec">
${pu:reqSet('presentProduct', pu:get('com.yaodian100.ec.product.entity.Product', pspec.productId)) }
	<tr>
	<td><yaodian100:productImg productId="${presentProduct.productId}" postfix="m75" /></td>
	<td>
	
	${presentProduct.productName }
	</td><td>
	<select name="presentQty">
		<option value="${pspec.specificationId }@0">0</option>
		<c-rt:forEach begin="1" end="${maxPresentQty}" var="specQty">
		<option value="${pspec.specificationId }@${specQty}">${specQty }</option>
		</c-rt:forEach>
	</select>
	</td></tr>
</c-rt:forEach>
</table>
</td></tr></table>
<input type="hidden" name="orderId" value="${param.orderId }"/>
<table class="tb-data" >
<tr>
<th>
原始
</th>
<th>修改为</th>
<th>
调整结果
</th>

</tr>
<c-rt:forEach items="${ops}" var="op">
<c-rt:forEach items="${op.orderProductDetail }" var="opd">
	<tr>
	<td>
	<table>
	<tr>
	<th>商品编号</th><th>商品名称</th><th>数量</th><th>单价</th><th>合计</th>
	</tr>
	<tr>
	<td>${opd.prodId }</td>
	<td>${opd.prodName }-${opd.prodSpecName }</td>
	<td>${opd.qty }</td>
	<td>${opd.unitPrice }</td>
	<td>${opd.amount }</td>
	</tr>
	</table>
	</td>
	<td>编辑</td>
	<td>
	<table>
	<tr>
	<th>商品编号</th><th>商品名称</th><th>数量</th><th>单价</th><th>合计</th>
	</tr>
	<c-rt:set var="prodUnitPrice" value="${opd.amount/opd.qty}"/>
	<c-rt:forEach begin="1" end="${opd.qty}">
	<tr>
		<td>${opd.prodId }</td>
	<td>${opd.prodName }-
	<c-rt:if test="${!empty opd.outerCid}">
	
	<c-rt:forEach items="${tmallProducts}" var="tmallProd">
		<c-rt:if test="${tmallProd.numIid==opd.outerProdId}">
			<select name="specProp">
				<c-rt:forEach items="${tmallProd.skus}" var="sku">
				${pu:reqSet('outerSpecName', '') }
				<c-rt:forEach items="${pvs[sku.skuId] }" var="pv">
					
					<c-rt:set var="outerSpecName" scope="request">
					${outerSpecName } ${pv.name }
					</c-rt:set>
					</c-rt:forEach>
					<c-rt:if test="${sku.quantity<pu:toLong(tmall_safeQty.memo1)}">
						<c-rt:set var="optionAttr" scope="request">
						disabled="disabled" <c-rt:if test="${pu:toLong(sku.outerId) eq pu:toLong(opd.prodSpecId) }">selected="selected"</c-rt:if>
						</c-rt:set>
					</c-rt:if>
					<c-rt:if test="${sku.quantity>=pu:toLong(tmall_safeQty.memo1)}">
					<c-rt:set var="optionAttr" scope="request">
					 <c-rt:if test="${pu:toLong(sku.outerId) eq pu:toLong(opd.prodSpecId) }">selected="selected"</c-rt:if>
					</c-rt:set>
					</c-rt:if>
					<option value="1@${opd.orderProdId}@${opd.orderDetailId}@${prodUnitPrice }@${sku.outerId }@${sku.skuId}@${outerSpecName}" ${optionAttr }>
					${outerSpecName }
					</option>
				</c-rt:forEach>
			</select>
		</c-rt:if>
		
	</c-rt:forEach>
	</c-rt:if>
	<c-rt:if test="${empty opd.outerCid}">
			${opd.prodSpecName }
		</c-rt:if>
	</td>
	<td>1</td>
	<td>${opd.unitPrice }</td>
	<td>${opd.amount }</td>
	</tr>
	</c-rt:forEach>
	</table>
	</td>
	</tr>
</c-rt:forEach>
</c-rt:forEach>
</table>
<input type="button" value="送出" onclick="checkForm()"/>
<input type="reset" value="重置"/>
</form>